import java.util.*;

public class Review {
    public static void main(String[] args) {
        List<String> l = new LinkedList<>();
        l.add("a");
        l.add("b");
        l.add("c");
        for ( String e : l) {
            System.out.println(e);
        }
        l.remove("a");
        for ( String e : l) {
            System.out.println(e);
        }
        System.out.println("===================");
        Iterator<String> it = l.iterator();
        while(it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println("=============================HashSet=================");
        //无序号不可重复
        Set set = new HashSet();//HashSet
        A a = new A("zhangsan",55);
        A b = new A("lisi",44);
        A c = new A("zhaoliu",34);
        A d = new A("zhaoeeeee",23);

        set.add(a);
        set.add(b);
        set.add(c);
        set.add(d);
        set.add(d);

        for (Object e : set) {
            System.out.println(e);
        }
        System.out.println("HashSet集合中的元素个数：" + set.size());
        System.out.println("==========================================TreeSet===============================");
        //TreeSet 需要有比较规则 两种方式 new TreeSet的时候通过构造方法传一个比较器这个比较器实际上是一个类继承了比较器接口
        //或者写 在添加元素的类实现可比较的接口 并且得要实现compareTo方法传入比较规则
        //HashSet 和 HashMap中的 equals 和 HashCode方法必须同时重写
        Set<A> treeSet = new TreeSet<>();
        treeSet.add(a);
        treeSet.add(b);
        treeSet.add(c);
        treeSet.add(d);
        for (A e : treeSet) {
            System.out.println(e);
        }
        System.out.println("===================Iterator遍历===========================");
        Iterator<A> it2 = treeSet.iterator();
        while (it2.hasNext()) {
            System.out.println(it2.next());

        }
        System.out.println("========================HashMap================================");
        Map<A,A> map = new HashMap<>();
        map.put(a,a);
        map.put(b,b);
        map.put(c,c);
        map.put(d,d);
        map.put(d,a);
        System.out.println("map size is " + map.size() );

        Set<Map.Entry<A,A>> set1 = map.entrySet();



    }

}
class Ac implements Comparator<A> {

    @Override
    public int compare(A o1, A o2) {
        return o1.num - o2.num;
    }
}


class  A implements Comparable<A>{
    String name;
    int num;

    public A() {
    }


    public A(String name, int num) {
        this.name = name;
        this.num = num;
    }

    @Override
    public String toString() {
        return "A{" +
                "name='" + name + '\'' +
                ", num=" + num +
                '}';
    }

    @Override
    public int compareTo(A o) {
        return o.num - this.num;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        A a = (A) o;
        return num == a.num && Objects.equals(name, a.name);
    }
    @Override
    public int hashCode() {
        return Objects.hash(name, num);
    }
}